package com.test.mylotterysystem.service.ActivityStatusChange.Operator;

import com.test.mylotterysystem.dao.DO.ActivityPrizeDO;
import com.test.mylotterysystem.dao.Mapper.ActivityPrizeMapper;
import com.test.mylotterysystem.service.DTO.ConvertActivityStatusDTO;
import com.test.mylotterysystem.service.serviceEnum.ActivityPrizeStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ActivityPrizeOperator extends AbstractOperator {
    @Autowired
    private ActivityPrizeMapper activityPrizeMapper;

    @Override
    public Integer sequence() {
        return 1;
    }

    @Override
    public Boolean needConvert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        ActivityPrizeDO activityPrizeDO = activityPrizeMapper.selectByAPId(convertActivityStatusDTO.getActivityId(), convertActivityStatusDTO.getPrizeId());
        if (activityPrizeDO.getStatus().equalsIgnoreCase(ActivityPrizeStatusEnum.COMPLETE.getStatus())) {
            return false;
        }
        return true;
    }

    @Override
    public Boolean convert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        try {
            activityPrizeMapper.updateStatus(convertActivityStatusDTO.getActivityId()
                    , convertActivityStatusDTO.getPrizeId(), convertActivityStatusDTO.getTargetPrizeStatus().name());
            return true;
        } catch (Exception e) {
            log.error("转换失败");
            return false;
        }
    }
}
